//
//  WeauctionPublishConditionsCell.m
//  WeGalaxy
//
//  Created by Zheng on 2017/6/30.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "WeAuctionPublishConditionsCell.h"

@implementation WeAuctionPublishConditionsCell

- (void)textDidChange:(UITextField *)textField {
    if ([textField.text isEqualToString:@"¥"] || [textField.text isEqualToString:@"¥ "]) {
        textField.text = nil;
    } else {
        NSCharacterSet *set = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
        NSString *text = [textField.text stringByTrimmingCharactersInSet:set];
        textField.text = [NSString stringWithFormat:@"¥ %@",text];
    }
}

#pragma mark - 子视图
- (void)subviewsInContentView {
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.contentLbl];
    [self.contentView addSubview:self.contentTxf];
    
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50);
        make.centerY.equalTo(self);
    }];
    
    [_contentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(130);
        make.centerY.equalTo(self);
    }];
    
    [_contentTxf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(130);
        make.right.mas_equalTo(-10);
        make.top.bottom.equalTo(self);
    }];
}

- (UITextField *)contentTxf {
    if (!_contentTxf) {
        _contentTxf = [UITextField new];
        _contentTxf.placeholder = @"¥ 0";
        _contentTxf.keyboardType = UIKeyboardTypeNamePhonePad;
        [_contentTxf addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
    }
    return _contentTxf;
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [UILabel new];
        _titleLbl.font = kCX_FONT(14);
    }
    return _titleLbl;
}

- (UILabel *)contentLbl {
    if (!_contentLbl) {
        _contentLbl = [UILabel new];
        _contentLbl.font = kCX_FONT(14);
    }
    return _contentLbl;
}

#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.separatorInset = UIEdgeInsetsMake(0, 25, 0, 0);
        [self subviewsInContentView];
    }
    return self;
}




@end
